package com.fosung.frame.common.utils;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;

public class SendSmsUtils {

	@SuppressWarnings("rawtypes")
	public static String sendSms(String url, String message, String number) throws AxisFault {
		RPCServiceClient serviceClient = new RPCServiceClient();
		Options options = serviceClient.getOptions();
		options.setManageSession(true);
		options.setTimeOutInMilliSeconds(10000L);
		options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, true);
		EndpointReference targetEPR = new EndpointReference(url);
		options.setTo(targetEPR);
		// 指定getGreeting方法的参数值
		String str = getSmsContent(message, number);
		Object[] opAddEntryArgs = new Object[] { str };
		// 指定getGreeting方法返回值的数据类型的Class对象
		Class[] classes = new Class[] { String.class };
		// 指定要调用的getGreeting方法及WSDL文件的命名空间
		QName opAddEntry = new QName("http://service.com", "userAppSmsSend");
		Object resObj = serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)[0];
		System.out.println("返回结果：" + resObj.toString());
		serviceClient.cleanupTransport();
		return "";
	}

	public static String getSmsContent(String message, String number) {
		StringBuilder str = new StringBuilder();
		str.append("<request>");
		str.append("<strContent>").append(message).append("</strContent>");
		str.append("<strmobileNumber>").append(number).append("</strmobileNumber>");
		str.append("<senderName>FosungFrame</senderName>");
		str.append("<userId>000015181</userId>");
		str.append("<customerId>frame</customerId>");
		str.append("<customerPassport>ypo4h7zw</customerPassport>");
		str.append("</request>");
		System.out.println("发送的信息：" + str.toString());
		return str.toString();
	}
}
